*******************************************************************************
To replicate our findings, perform the following steps:

- Edit the first line of rundirectory.do to point to the location of the 
replication/ folder in your file system.
- Ensure that the replication folder contains the following subfolders:
replication/build/inputs
replication/build/inputs/census
replication/build/inputs/shapefiles
replication/build/temp
replication/build/scripts
replication/build/outputs
replication/analysis/temp
replication/analysis/scripts
replication/analysis/outputs
replication/analysis/outputs/tables
replication/analysis/outputs/graphs
- Run rundirectory.do

All the tables and graphs in the paper are saved in the analysis/outputs folder.*******************************************************************************

*******************************************************************************
Description of Directories and Files

1. Data

- build/inputs
Contains the input data for all analyses in the paper.

- build/inputs/census
Contains the census microdata for 1980, 1991, 2000, and 2010. These datasets 
include variables that have been harmonized and are limited to those used in 
our analysis.

- build/inputs/spei12_yearly_mca8010
Cointains the data with the monthly Standardised Precipitation 
Evapotranspiration Index (SPEI) for each  MCA.

- build/inputs/geo_codes_sat_cities
Contains the correspondence between municipalities, Minimum Comparable Areas 
(MCAs), and other geographic regions.

- build/inputs/shapefiles
Contains the shapefiles required to create Figure 1, which displays the map 
of the variation in −1×SPEI over the analysis period.

- build/temp and analysis/temp
Contain intermediate data files generated by other do files.

2. Codes

-build/scripts
Contains the do-files for cleaning and preparing the dataset used in the 
analysis.

-build/scripts/droughts_index.do
Code to calculate the average SPEI drought index for the years of interest.

-build/scripts/shift_share_instrument.do
Code to create the shift share instruments.

-build/scripts/cities_panel.do
Code to construct the city panel with labor and housing outcomes for the 
main specification.

-build/scripts/combes_first_step.do
Code to perform the first step of Combes et al. (executed within cities_panel_short.do)

-build/scripts/dataset_preparation.do
Code to prepare the final dataset for analysis, including outcomes, 
instruments, endogenous variables, and controls.

-analysis/scripts
Contains the do-files for the estimation and the analysis of results.

-analysis/scripts/balance_covariates.do
Code to implement balance tests from Borusyak et al. (Table 1). 

-analysis/scripts/map.do
Code to create the map of variation in -1*SPEI over the period of analysis (Figure 1).

-analysis/scripts/first_stage_rural_emig.do
Code to estimate the effects of precipitations on rural emigration
(Table 2 - Panel A and Appendix Table 7 - Panel A).

-analysis/scripts/descriptive_stats_1.do
Code to calculate the descriptive statistics of the labor and housing markets
outcomes of residents (Appendix Table 1).

-analysis/scripts/descriptive_stats_2.do
Code to calculate the characteristics of internal migrants who arrived in 
urban areas in the 2000–2010 period (Appendix Table 2).

-analysis/scripts/implementation.do
Code to perform regressions at the rural-area level following Borusyak et al., 
run the first stage with city-level transformations, 
estimate the effects of rural immigration on labor market and housing outcomes, 
conduct heterogeneous effects, and conduct robustness tests.

-analysis/scripts/format_tables.do
Code to format nearly all tables and convert them to .tex files.

3. Results

-analysis/outputs/tables
Contains all the tables from the paper in .tex format.

-analysis/outputs/graphs
Contains all the graphs from the paper.

*******************************************************************************